using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.UI;

public class MainUIManager : MonoBehaviour
{
    public Slider loadingSlider;
    public GameObject loading;
    private AsyncOperation operation;
    private bool isLoading = false;
    private float startTime = 0;

    private void Start()
    {
        loading.SetActive(false);
    }
    // Update is called once per frame
    void Update()
    {
        if (isLoading)
        {
            loadingSlider.value = (Time.time - startTime) / 2;
            if (Time.time - startTime > 2 && operation.progress >= 0.9f)
            {
                isLoading = false;
                operation.allowSceneActivation = true;
            }
        }
        
    }

    public void startGame()
    {
        startTime = Time.time;
        isLoading = true;
        StartCoroutine(loadScene());
    }

    IEnumerator loadScene()
    {
        operation = SceneManager.LoadSceneAsync(1);
        operation.allowSceneActivation = false;
        yield return operation;
    }

    public void quitGame()
    {
        Application.Quit();
    }
}
